package com.taxi.controller;

import com.taxi.constant.DriverCarConstants;
import com.taxi.dto.DriverCarBindingRelationship;
import com.taxi.dto.DriverUser;
import com.taxi.dto.DriverUserWorkStatus;
import com.taxi.response.DriverUserExistsResponse;
import com.taxi.response.OrderDriverResponse;
import com.taxi.result.Result;
import com.taxi.service.DriverUserService;
import com.taxi.service.IDriverCarBindingRelationshipService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: aniu
 * @Date: 2023/9/27
 * @ClassName: DriverUserController
 * @Description: Write class functionality and purpose here.
 * @Version: 1.0
 */
@RestController
public class DriverUserController {
    @Autowired
    private DriverUserService driverUserService;

    @Autowired
    private IDriverCarBindingRelationshipService driverCarBindingRelationshipService;

    /**
     * 根据id查询司机信息
     */
    @GetMapping("/get-driver-info/{driverId}")
    public Result<DriverUser> getDriverInfo(@PathVariable("driverId") Long driverId){
        return driverUserService.getDriverInfoById(driverId);
    }

    /**
     * 查找所有司机
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/driver-user/list")
    public Result getDriverUserList(@RequestParam int page, @RequestParam int limit, @RequestParam(required = false) String address, @RequestParam(required = false) String phone){
        return driverUserService.getDriverUserList(page, limit, address, phone);
    }

    /**
     * 添加或者修改司机信息
     * @param driverUser
     * @return
     */
    @ApiOperation("添加或者修改司机信息")
    @PostMapping("/user")
    public Result addOrUpdateDriverUser(@RequestBody DriverUser driverUser){
        return driverUserService.addDriverUser(driverUser);
    }

    /**
     * 根据条件查询司机
     * @param driverPhone
     * @return
     */
    @ApiOperation("根据条件查询司机")
    @GetMapping("/check-driver/{driverPhone}")
    public Result<DriverUserExistsResponse> getUser(@PathVariable("driverPhone") String driverPhone){
        DriverUser driverUserDB = driverUserService.getDriverByPhone(driverPhone);

        int ifExists= DriverCarConstants.DRIVER_EXISTS;
        if(ObjectUtils.isEmpty(driverUserDB)){
            ifExists=DriverCarConstants.DRIVER_NOT_EXISTS;
        }

        DriverUserExistsResponse response = new DriverUserExistsResponse();
        response.setIfExists(ifExists);
        response.setDriverPhone(driverPhone);

        return Result.ok(response);
    }

    @ApiOperation("根据车牌号查询订单需要的司机信息")
    @GetMapping("/get-available-driver/{vehicleNo}")
    public Result getAvailableDriver(@PathVariable("vehicleNo") String vehicleNo){
        return driverUserService.getAvailableDriver(vehicleNo);
    }

    @ApiOperation("根据司机手机号查询司机和车辆绑定关系")
    @GetMapping("/driver-car-binding-relationship/{driverPhone}")
    public Result<DriverCarBindingRelationship> getDriverCarRelationShip(@PathVariable String driverPhone){
        return driverCarBindingRelationshipService.getDriverCarRelationShipByDriverPhone(driverPhone);
    }

    /**
     * 增加司机总单数
     * @param driverId
     * @return
     */
    @GetMapping("/add-driver-total-orders/{driverId}")
    public Result addDriverTotalOrders(@PathVariable("driverId") Long driverId){
        return driverUserService.addDriverTotalOrders(driverId);
    }

}
